{% extends 'admin/admin_base.html' %}
{% block title %}{% if 'create' == cha[0] %}增加{% elif 'change' == cha[0] %}修改{% else %}查看{% endif %}-用户组{% endblock %}
{% block head %}
    {{ super() }}
{% endblock %}
{% block body %}
    <ul class="nav nav-tabs">
        {% if 'change' == cha[0] %}
            <li onclick="chick_1()"><a href="#" >保存</a></li>
        {% elif 'create' == cha[0] %}
            <li onclick="chick()"><a href="#" >保存</a></li>
        {% endif %}

        <li><a href="{{ url_for('mygroup.index') }}">取消</a></li>
    </ul>
    <div class="admin-form form-horizontal">
        {% if 'change' == cha[0] %}
        <div class="form-group">
            <label for="user" class="col-md-2 control-label">ID</label>
            <div class="col-md-10" style="width: 30%">
            <input class="form-control" id="ids" name="ids" type="text" value="{{ cha[1]['id'] }}" readonly="true"></div>
        </div>
        {% endif %}
        <div class="form-group">
            <label for="user" class="col-md-2 control-label">名称</label>
            <div class="col-md-10" style="width: 30%">
            {% if 'change' == cha[0] %}
                <input class="form-control" id="user" name="user" type="text" value="{{ cha[1]['name'] }}"></div>
            {% elif 'check' == cha[0] %}
                <input class="form-control" id="user" name="user" type="text" value="{{ cha[1]['name'] }}" readonly="true"></div>
            {% else %}
            <input class="form-control" id="user" name="user" type="text"></div>
            {% endif %}
        </div>
        <label class="col-md-2 control-label"></label>
            <div class="col-md-10" style="width: 30%">
                <p id="message1" style="color: red;"></p>
            </div>
    </div>
    <input id="photo" style="position: absolute; top: -9999px; left: -9999px;" value="{{ cha[0] }}"/>
{% endblock %}
{% block tail %}
        {{ super() }}
{#    <!--{{ lib.form_js() }}-->#}
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
    <script type="text/javascript">
        function chick() {
            var name = document.getElementById('user').value;
            var gg = document.getElementById('photo').value;
            $.ajax({
                headers: {"X-CSRFToken": '{{ csrf_token }}'},
                url: "group_1/",
                type: 'POST',
                tradition: true,
                dataType: 'json',
                data: {'name': name,'cha':gg},
                success: function (data) {
                    if (data.state == 'success') {
                        document.getElementById("message1").innerHTML = '添加成功';
                        window.location.href = data.url
                    } else if (data.state == 'fail') {
                        $('#message1').html(data.message);
                        setTimeout(function () {
                            $('#message1').html('');
                        }, 3000)
                    }
                }
            })
        }
        function chick_1() {
            var id = document.getElementById('ids').value;
            var name = document.getElementById('user').value;
            var gg = document.getElementById('photo').value;
            $.ajax({
                headers: {"X-CSRFToken": '{{ csrf_token }}'},
                url: "group_1/",
                type: 'POST',
                tradition: true,
                dataType: 'json',
                data: {'name': name,'id': id,'cha':gg},
                success: function (data) {
                    if (data.state == 'success') {
                        document.getElementById("message1").innerHTML = '修改成功';
                        window.location.href = data.url
                    } else if (data.state == 'fail') {
                        $('#message1').html(data.message);
                        setTimeout(function () {
                            $('#message1').html('');
                        }, 3000)
                    }
                }
            })
        }
    </script>
{% endblock %}